package davion.study.jwtlearn.service;

import davion.study.jwtlearn.pojo.User;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @author: Davion
 * @date: 2020.6.22
 * @description:
 */
@Service
public class UserService {
    static List<User> users = new ArrayList<>();

    static {
        users.add(new User("1", "Davion", "123456"));
        users.add(new User("2", "Alice", "123456"));
        users.add(new User("3", "Jackson", "123456"));
        users.add(new User("4", "Justin", "123456"));
        users.add(new User("5", "Martin", "123456"));

    }

    public User findUserById(String userId) {
        for (User user : users) {
            if (user.getId().equals(userId)){
                return user;
            }
        }
        return null;
    }

    public User findByUsername(String username) {
        for (User user : users) {
            if (user.getUsername().equals(username)){
                return user;
            }
        }
        return null;
    }
}
